package com.hci.leukemiaapp;

//import com.example.ContactBadge.R;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.provider.ContactsContract.Contacts;
import android.util.Log;
import android.view.View;
import android.widget.QuickContactBadge;
import android.widget.Toast;

public class PhysiciansActivity extends Activity {
    /** Called when the activity is first created. */
	private static final int CONTACT_PICKER_RESULT = 1001;
	private QuickContactBadge badge1;
	private QuickContactBadge badge2;
	private int numOfContacts = 0;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.badge);
        
        badge1 = (QuickContactBadge) findViewById(R.id.badge_1);
        badge2 = (QuickContactBadge) findViewById(R.id.badge_2);
        
        badge1.assignContactFromPhone("555-555-5555", true); 
        badge1.setMode(ContactsContract.QuickContact.MODE_LARGE); 
        
        badge1.setVisibility(4);
        badge2.setVisibility(4);
    }
    
    public void onPickContact(View v){
    	Intent contactPickerIntent = new Intent(Intent.ACTION_PICK, Contacts.CONTENT_URI);  
        startActivityForResult(contactPickerIntent, CONTACT_PICKER_RESULT);
    }
    
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
        if (resultCode == RESULT_OK) {  
            switch (requestCode) {  
            case CONTACT_PICKER_RESULT:  
                // handle contact results
            	numOfContacts += 1;
            	if(numOfContacts > 2)
            		break;            	
            	if(numOfContacts == 1){
            		badge1.setVisibility(0);
            	}
            	else if(numOfContacts == 2){
            		badge2.setVisibility(0);
            	}
            	Context context = this.getApplicationContext();
            	CharSequence text = "New contact added";
            	int duration = Toast.LENGTH_SHORT;
            	Toast toast = Toast.makeText(context, text, duration);
            	toast.show();
                break;  
            }  
      
        } else {  
            // gracefully handle failure  
            Log.w(null, "Warning: activity result not ok");  
        }  
    }  
}